package com.archie.xunji.map.tools;

import com.archie.xunji.map.entity.DiscoverResultEntity;
import com.archie.xunji.map.entity.KindResultEntity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/10.
 */
public final class ParseJsonUtls {

    public static List<DiscoverResultEntity> parseDiscoverResultEntity(String str){
        List<DiscoverResultEntity> ret = null;

        if(str != null){
                ret = new ArrayList<DiscoverResultEntity>();
            try {
                JSONObject object = new JSONObject(str);
                JSONObject object1 = object.getJSONObject("result");
                JSONArray array = object1.getJSONArray("data");

                for(int i=0;i<array.length();i++){

                    DiscoverResultEntity entity = new DiscoverResultEntity();
                    entity.parseEntity(array.getJSONObject(i));
                    ret.add(entity);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        return ret;
    }


    public static List<KindResultEntity> parseKindResultEntity(String str){
        List<KindResultEntity> ret = null;

        if(str != null){
            ret = new ArrayList<KindResultEntity>();

            try {
                JSONObject object = new JSONObject(str);
                JSONObject object1 = object.getJSONObject("result");
                JSONArray array = object1.getJSONArray("data");

                for (int i = 0; i < array.length(); i++) {
                    JSONObject jsonObject = array.getJSONObject(i);

                    KindResultEntity entity = new KindResultEntity();
                    entity.parseEntity(jsonObject);

                    ret.add(entity);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        return ret;
    }
}
